/*
* coder: Dzlua
* email: 505544956@qq.com
* time : 2018-04-13 15:20
*/
#pragma once
#ifndef __WINDOW_HPP__
#define __WINDOW_HPP__

UI_BEGIN_NAMESPACE

/*
* window
*/
class CWindow
    : public IWindow
    , public std::enable_shared_from_this<CWindow> {
protected:
    CWindow() {}
public:
    static std::shared_ptr<CWindow> instance() {
        return std::make_shared<CWindow>();
        //return std::shared_ptr<CWindow>(new CWindow());
    }
public:
    virtual BOOL TranslateAccelerator(MSG* pMsg) {
        /*
        * for translate accelerator.
        */
        auto arr = this->GetTranslateAcceleratorArray();
        for (auto itor = arr.begin(); itor != arr.end(); ++itor) {
            if ( (*itor)(pMsg) ) return TRUE;
        }
        return FALSE;
    }
    virtual BOOL PreMessageHandler(MSG* pMsg) {
        /*
        * for pre message handler.
        */
        auto arr = this->GetMessageFilterArray();
        for (auto itor = arr.begin(); itor != arr.end(); ++itor) {
            if ( (*itor)(pMsg) ) return TRUE;
        }
        return FALSE;
    }
    // ATL::CWindowImpl
    virtual void OnFinalMessage(_In_ HWND /*hWnd*/) {
        CManager::instance()->OnWindowDestroy(shared_from_this());
	}
public:
    DECLARE_WND_CLASS(_T("UI::Window"))
    BEGIN_MSG_MAP(CWindow)
        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        MESSAGE_HANDLER(WM_NCDESTROY, OnDestroy)
    END_MSG_MAP()
public:
    LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
        bHandled = FALSE;
		return 1;
	}
    LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
        bHandled = FALSE;
		return 1;
	}
};

UI_END_NAMESPACE

#endif
